package com.bajie.bjlisten.sevice;


import com.bajie.bjlisten.entity.BjClassifyDto;
import com.bajie.bjlisten.mapper.BjUserInterestMapper;
import com.bajie.bjlisten.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

@Service
public class BjUserInterestService {

    @Autowired
    BjUserInterestMapper bjUserInterestMapper;

    @Transactional
    public int saveBjUserInterest(String userId, List<String> classifys) {
        bjUserInterestMapper.deleteByUserId(userId);
        if (StringUtils.isNotEmpty(classifys)) {
            return bjUserInterestMapper.saveUserInterest(userId, classifys);
        } else
            throw new RuntimeException();
    }


    @Transactional
    public Boolean addInterestClassifys(BjClassifyDto bjClassifyDto) {
        int value = saveBjUserInterest(bjClassifyDto.getUserId(), bjClassifyDto.getClassifys());
        return value > 0 ? true : false;

    }


}
